﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Dynamic;
using System.ComponentModel;
using CCH.Entity;

namespace CCH.DAO
{
    [DataObject(true)]
    public class boardDAO
    {
        private Entities model = new Entities();

        public IQueryable<board> Get_board_AllData(string boa_isreply)
        {

            var data = from d in model.board
                       where d.state == "1"
                       select d;

            if (boa_isreply != "0")
            {
                data = data.Where(o => o.boa_isReply == boa_isreply);
            }

            return data.OrderByDescending(o => o.boa_datetime);
        }

        public IQueryable<board> Get_board_AllData(string boa_isreply, int startRowIndex, int maximumRows)
        {
            return Get_board_AllData(boa_isreply).Skip(startRowIndex).Take(maximumRows);
        }

        public int Get_board_AllData_Count(string boa_isreply)
        {
            return Get_board_AllData(boa_isreply).Count();
        }

        public board Get_board(int boa_no)
        {
            return (from d in model.board where d.boa_no == boa_no select d).FirstOrDefault();
        }

        public void Add_board(board d)
        {
            model.board.AddObject(d);
            Update();
        }

        public void Delete_board(int boa_no, int peo_uid)
        {
            board d = Get_board(boa_no);
            d.state = "2";
            d.boa_delID = peo_uid;
            d.boa_delDT = DateTime.Now;
            Update();
        }

        public void Update()
        {
            model.SaveChanges();
        }
    }
}
